package com.yyw.gulimall.elasticsearch.controller.index;

import com.yyw.gulimall.elasticsearch.service.index.IndexSearchService;
import com.yyw.gulimall.elasticsearch.vo.IndexSearchParamsVo;
import com.yyw.gulimall.elasticsearch.vo.IndexSearchResultVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 易煜玮
 * @ClassName IndexController.java
 * @Description 搜索页首页
 * @createTime 2020年11月30日 21:17:00
 */
@Controller
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class IndexController {

    private final IndexSearchService indexSearchService;

    /**
     * 搜索首页查询
     *
     * @param paramsVo
     * @param model
     * @return
     */
    @GetMapping("/list.html")
    public String index(IndexSearchParamsVo paramsVo, Model model, HttpServletRequest request) {
        // 获取请求中的所有请求参数
        paramsVo.setQuery_path(request.getQueryString());
        IndexSearchResultVo result = indexSearchService.search(paramsVo);
        model.addAttribute("result", result);
        return "index";
    }
}
